/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package auctions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

/**
 *
 * @author hangsu
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // System.out.println("main");
        double[] avgRegret = new double[8];
        double[] avgProfit = new double[8];
        int simul_times = 1;
        for (int simul = 0; simul < simul_times; simul++) {
            int auction_environment = 1;
            int N = 8;
            int M = 5;
            ScheduleAuctionhouse house;
            Random r = new Random();
            ArrayList<ScheduleAgent> agents = new ArrayList<ScheduleAgent>();
            int lamda;
            double[] utils = new double[M];
            if (auction_environment == 0) {
                for (int i = 0; i < N; i++) {
                    lamda = r.nextInt(M) + 1;
                    for (int j = 0; j < M; j++) {
                        utils[j] = (double) r.nextInt(GlobalParameters.MaxPrice) + 1;
                    }
                    Arrays.sort(utils);
                    for (int k = 0; k < M / 2; k++) {
                        double tmp_d = utils[k];
                        utils[k] = utils[M - 1 - k];
                        utils[M - 1 - k] = tmp_d;
                    }
                    S2PSB_ScheduleAgent agent = new S2PSB_ScheduleAgent(i, N, M, lamda, M - 1, utils);
                    /* one agent running StraightMV, one agent running StraightMU,
                     * others using BASELINE as default */
                    if (i == 0) {
                        agent.setStrategy(S2PSB_ScheduleAgent.S2PSB_strategy.StraightMU);
                    }
                    if (i == 1) {
                        agent.setStrategy(S2PSB_ScheduleAgent.S2PSB_strategy.StraightMV);
                    }
                    agents.add(agent);
                }
                house = new ScheduleSimultaneousAuctionHouse(M, AuctionType.SEALEDBID);
            } else {
                for (int i = 0; i < N; i++) {
                    lamda = r.nextInt(M) + 1;
                   // lamda =2;
                    for (int j = 0; j < M; j++) {
                        utils[j] = (double) r.nextInt(GlobalParameters.MaxPrice) + 1;
                    }
                    Arrays.sort(utils);
                    for (int k = 0; k < M / 2; k++) {
                        double tmp_d = utils[k];
                        utils[k] = utils[M - 1 - k];
                        utils[M - 1 - k] = tmp_d;
                    }
                        			System.out.print("Agent #" + Integer.toString(i) + " Needs:" + Integer.toString(lamda) + " Util: ");
    			for (int n=0;n<utils.length;n++) {
  				System.out.print(Double.toString(utils[n])+", ");
   			}
    			System.out.print("\n");
                    SE2PSB_ScheduleAgent agent = new SE2PSB_ScheduleAgent(i, N, M, lamda, M - 1, utils);
                    /* one agent running StraightMV, one agent running StraightMU,
                     * others using BASELINE as default */
                   if(i==0){
                        agent.setStrategy(SE2PSB_ScheduleAgent.SE2PSB_strategy.ExpectedMU);
                      agent.setPricePrediction(GlobalParameters.PointPricePrediction_SE2PSB_StraighMV);
                   }
//                    if (i%4 == 3) {
//                        agent.setStrategy(SE2PSB_ScheduleAgent.SE2PSB_strategy.WEIGHTED);
//                        agent.setPriceDistribution(GlobalParameters.PointPricePrediction_SE2PSB_StraightMU);
//                    }
//                     if (i%4 == 2) {
//                     agent.setStrategy(SE2PSB_ScheduleAgent.SE2PSB_strategy.StraightMU);
//                     agent.setPricePrediction(GlobalParameters.PointPricePrediction_SE2PSB_StraighMV);
//                   }
//                    if (i%4 == 1) {
//                        agent.setStrategy(SE2PSB_ScheduleAgent.SE2PSB_strategy.WEIGHTED_EXPOSURE_PADDING);
//                        agent.setPriceDistribution(GlobalParameters.PointPricePrediction_SE2PSB_StraightMU);
//                    }
//                     if (i%4 == 0) {
//                     agent.setStrategy(SE2PSB_ScheduleAgent.SE2PSB_strategy.StraightMV);
//                     agent.setPricePrediction(GlobalParameters.PointPricePrediction_SE2PSB_StraighMV);
//                   }
                    agents.add(agent);
                }
                house = new ScheduleSequentialAuctionHouse(M, AuctionType.SEALEDBID);

            }
            house.setAgents(agents);
            house.startAuctions();
            house.writeResult("result.xml");
            System.out.println("Main auctions closed!  Beginning regret simulations...");
            double[] regrets = StrategyEvaluator.computeSimulatedRegret(agents);
            for (int i = 0; i < N; i++) {
                avgRegret[i] += regrets[i];
                avgProfit[i] += agents.get(i).getBidderResult().getProfit();
            //System.out.println("Agent #" + Integer.toString(i) + " regret=" + Double.toString(((SE2PSB_ScheduleAgent)agents.get(i)).computeRegret()));
            }
        }
        for (int i = 0; i < 8; i++) {
            avgRegret[i] /= simul_times;
            avgProfit[i] /= simul_times;
            System.out.println("Agent #" + Integer.toString(i) + " regret=" + Double.toString(avgRegret[i]) + " profit=" + Double.toString(avgProfit[i]));
        }
    }
}
